package com.itrus.serviceframe;

import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class NameValuePair
{
  private String m_strName;
  private byte[] m_value;
  private int version = 0;

  public NameValuePair(NameValuePair paramNameValuePair)
  {
    this(paramNameValuePair.m_strName, paramNameValuePair.m_value);
  }

  public NameValuePair(String paramString1, String paramString2)
  {
    this(paramString1, paramString2.getBytes());
  }

  public NameValuePair(String paramString, byte[] paramArrayOfByte)
  {
    this.m_strName = paramString;
    this.m_value = paramArrayOfByte;
  }

  static int bytes2int(byte[] paramArrayOfByte)
  {
    return (((0xFF & paramArrayOfByte[0]) << 8 | 0xFF & paramArrayOfByte[1]) << 8 | 0xFF & paramArrayOfByte[2]) << 8 | 0xFF & paramArrayOfByte[3];
  }

  static short bytes2short(byte[] paramArrayOfByte)
  {
    return (short)((0xFF & paramArrayOfByte[0]) << 8 | 0xFF & paramArrayOfByte[1]);
  }

  static NameValuePair getInstance(InputStream paramInputStream, int paramInt)
    throws IOException, EOFException
  {
    byte[] arrayOfByte1 = new byte[2];
    read(paramInputStream, arrayOfByte1, 0, 2);
    int i = bytes2short(arrayOfByte1);
    byte[] arrayOfByte2 = new byte[i];
    read(paramInputStream, arrayOfByte2, 0, i);
    if (paramInt == 1)
      read(paramInputStream, arrayOfByte1, 0, 2);
    byte[] arrayOfByte3;
    for (int j = bytes2short(arrayOfByte1); ; j = bytes2int(arrayOfByte3))
    {
      byte[] arrayOfByte4 = new byte[j];
      read(paramInputStream, arrayOfByte4, 0, j);
      NameValuePair localNameValuePair = new NameValuePair(new String(arrayOfByte2), arrayOfByte4);
      localNameValuePair.setVersion(paramInt);
      return localNameValuePair;
      if ((paramInt != 2) && (paramInt != 3))
        break;
      arrayOfByte3 = new byte[4];
      read(paramInputStream, arrayOfByte3, 0, 4);
    }
    throw new IOException("不支持的协议版本，Version=[" + paramInt + "]。");
  }

  static void int2bytes(int paramInt, byte[] paramArrayOfByte)
  {
    paramArrayOfByte[3] = ((byte)(paramInt & 0xFF));
    paramArrayOfByte[2] = ((byte)((0xFF00 & paramInt) >> 8));
    paramArrayOfByte[1] = ((byte)((0xFF0000 & paramInt) >> 16));
    paramArrayOfByte[0] = ((byte)((0xFF000000 & paramInt) >> 24));
  }

  static void read(InputStream paramInputStream, byte[] paramArrayOfByte, int paramInt1, int paramInt2)
    throws IOException, EOFException
  {
    if (paramInt2 <= 0)
      return;
    do
    {
      int i = paramInputStream.read(paramArrayOfByte, paramInt1, paramInt2);
      if (i == -1)
        throw new EOFException();
      paramInt1 += i;
      paramInt2 -= i;
    }
    while (paramInt2 > 0);
  }

  static void short2bytes(int paramInt, byte[] paramArrayOfByte)
  {
    paramArrayOfByte[1] = ((byte)(paramInt & 0xFF));
    paramArrayOfByte[0] = ((byte)((0xFF00 & paramInt) >> 8));
  }

  public String getName()
  {
    return this.m_strName;
  }

  int getSize()
    throws IOException
  {
    int i;
    if (this.version == 1)
      i = 2 + (2 + this.m_strName.getBytes().length) + this.m_value.length;
    while (i > 2147483647)
    {
      throw new IllegalStateException();
      if ((this.version == 2) || (this.version == 3))
        i = 4 + (2 + this.m_strName.getBytes().length) + this.m_value.length;
      else
        throw new IOException("不支持的协议版本，Version=[" + this.version + "]。");
    }
    return i;
  }

  public byte[] getValue()
  {
    return this.m_value;
  }

  public int getVersion()
  {
    return this.version;
  }

  int serialize(OutputStream paramOutputStream)
    throws IOException
  {
    byte[] arrayOfByte1 = new byte[2];
    byte[] arrayOfByte2 = new byte[4];
    byte[] arrayOfByte3 = this.m_strName.getBytes();
    short2bytes(arrayOfByte3.length, arrayOfByte1);
    paramOutputStream.write(arrayOfByte1);
    paramOutputStream.write(arrayOfByte3);
    if (this.version == 1)
    {
      short2bytes(this.m_value.length, arrayOfByte1);
      paramOutputStream.write(arrayOfByte1);
      paramOutputStream.write(this.m_value);
      return 2 + (2 + arrayOfByte3.length) + this.m_value.length;
    }
    if ((this.version == 2) || (this.version == 3))
    {
      int2bytes(this.m_value.length, arrayOfByte2);
      paramOutputStream.write(arrayOfByte2);
      paramOutputStream.write(this.m_value);
      return 4 + (2 + arrayOfByte3.length) + this.m_value.length;
    }
    throw new IOException("不支持的协议版本，Version=[" + this.version + "]。");
  }

  public void setName(String paramString)
  {
    if (paramString == null)
      throw new IllegalArgumentException();
    this.m_strName = paramString;
  }

  public void setValue(String paramString)
  {
    if (paramString == null)
      throw new IllegalArgumentException();
    setValue(paramString.getBytes());
  }

  public void setValue(byte[] paramArrayOfByte)
  {
    if (paramArrayOfByte == null)
      throw new IllegalArgumentException();
    this.m_value = paramArrayOfByte;
  }

  public void setVersion(int paramInt)
  {
    this.version = paramInt;
  }

  public String toString()
  {
    if (this.m_value.length > 5242880)
      return this.m_strName + "\t" + "大字段";
    return this.m_strName + "\t" + new String(this.m_value);
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.serviceframe.NameValuePair
 * JD-Core Version:    0.6.2
 */